<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生人脸信息登记</title>    <link rel="stylesheet" href="style.css">
    <!-- Vue 3 CDN -->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <!-- 配置文件 -->
    <script src="config.js"></script>
</head>
<body>
    <div id="app">
        <div class="container">            <div class="form-container">
                <h1 class="title">学生人脸信息登记</h1>
                
                <!-- 导航链接 -->
                <div class="nav-links">
                    <a href="index.html" class="nav-link active">📝 学生登记</a>
                    <a href="signin.html" class="nav-link">✓ 学生签到</a>
                </div>
                
                <form @submit.prevent="submitForm" class="student-form">
                    <div class="form-group">
                        <label for="name">姓名：</label>
                        <input 
                            type="text" 
                            id="name" 
                            v-model="form.name" 
                            placeholder="请输入您的姓名"
                            required
                            class="form-input"
                        >
                        <span v-if="errors.name" class="error">{{ errors.name }}</span>
                    </div>
                      <div class="form-group">
                        <label for="class">班级：</label>
                        <select 
                            id="class" 
                            v-model="form.className" 
                            required
                            class="form-input"
                        >
                            <option value="">请选择班级</option>
                            <option v-for="cls in classList" :key="cls.name" :value="cls.name">{{ cls.name }}</option>
                        </select>
                        <span v-if="errors.class" class="error">{{ errors.class }}</span>
                    </div>
                    
                    <!-- 拍照区域 -->
                    <div class="form-group">
                        <label>人脸照片：</label>
                        <div class="camera-container">
                            <!-- 摄像头预览 -->
                            <div v-if="!capturedImage && !showCamera" class="camera-placeholder">
                                <button type="button" @click="startCamera" class="camera-btn">
                                    📷 打开摄像头拍照
                                </button>
                            </div>
                            
                            <!-- 摄像头视频流 -->
                            <div v-if="showCamera" class="camera-preview">
                                <video ref="video" autoplay playsinline class="video-preview"></video>
                                <div class="camera-controls">
                                    <button type="button" @click="capturePhoto" class="capture-btn">📸 拍照</button>
                                    <button type="button" @click="stopCamera" class="cancel-btn">❌ 取消</button>
                                </div>
                            </div>
                            
                            <!-- 已拍摄照片 -->
                            <div v-if="capturedImage" class="captured-photo">
                                <img :src="capturedImage" alt="拍摄的照片" class="photo-preview">
                                <div class="photo-controls">
                                    <button type="button" @click="retakePhoto" class="retake-btn">🔄 重新拍照</button>
                                    <button type="button" @click="clearPhoto" class="clear-btn">🗑️ 删除照片</button>
                                </div>
                            </div>
                        </div>
                        <span v-if="errors.photo" class="error">{{ errors.photo }}</span>
                    </div>
                    
                    <div class="form-group">
                        <button type="submit" class="submit-btn" :disabled="isSubmitting || !capturedImage">
                            <span v-if="isSubmitting">{{ uploadProgress }}%</span>
                            <span v-else>提交人脸信息</span>
                        </button>
                    </div>
                </form>
                
                <!-- 提交成功消息 -->
                <div v-if="successMessage" class="success-message">
                    {{ successMessage }}
                </div>
                
                <!-- 已提交的学生列表 -->
                <div v-if="submittedStudents.length > 0" class="students-list">
                    <h2>已登记学生</h2>
                    <div class="student-card" v-for="(student, index) in submittedStudents" :key="index">
                        <span class="student-name">{{ student.name }}</span>
                        <span class="student-class">{{ student.class }}</span>
                        <span class="student-time">{{ student.time }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="app.js"></script>
</body>
</html>
